﻿namespace VariableNamingAndSimplifiedExpressions
{
    using System;

    public class Rectangle
    {
        private double width;
        private double height;

        public Rectangle(double width, double height)
        {
            this.Width = width;
            this.Height = height;
        }

        public double Height
        {
            get
            {
                return this.height;
            }

            set
            {
                if (value > 0)
                {
                    this.height = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Height must be positive number.");
                }
            }
        }

        public double Width
        {
            get
            {
                return this.width;
            }

            set
            {
                if (value > 0)
                {
                    this.width = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Width must be positive number.");
                }
            }
        }

        public static Rectangle GetRotated(Rectangle rectangle, double angle)
        {
            double angleCos = Math.Cos(angle);
            double angleCosAbs = Math.Abs(angleCos);
            double angleSin = Math.Sin(angle);
            double angleSinAbs = Math.Abs(angleSin);
            double newWidth = (angleCosAbs * rectangle.Width) + (angleSinAbs * rectangle.Height);
            double newHeight = (angleSinAbs * rectangle.Width) + (angleCosAbs * rectangle.Height);
            Rectangle rotatedRectangle = new Rectangle(newWidth, newHeight);

            return rotatedRectangle;
        }
    }
}